package cn.edu.scau.cmi.zhouxinyue.safeComposite;

import java.util.ArrayList;

public class safeComposite extends safeComponent{
	private int Pnumber=0;
	private int Tnumber=0;
	private int JudgeLeaf=0;
	private String name;
	private safeComponent parent=null;
	private ArrayList<safeLeaf> allPerson=new ArrayList<>();
	private ArrayList<safeComponent> allTeam=new ArrayList<>();
	
	public int JudgeLeaf() {
		return JudgeLeaf;
	}
	
	public safeComposite(String name,safeComponent parent) {
		this.name=name;
		this.parent=parent;
	}

	@Override
	public safeComponent getParent() {
		// TODO Auto-generated method stub
		return parent;
	}
	public String getName() {
		return name;
	}

	public safeComponent addPerson(safeLeaf person) {
		allPerson.add(person);
		Pnumber++;
		return parent;
	}

	public safeComponent addTeam(safeComponent team) {
		allTeam.add(team);
		Tnumber++;
		return parent;
	}

	public safeComponent deletePerson(safeLeaf person) {
		int judge=0;
		for(int i=0;i<allPerson.size();i++) {
			if(person.getName().equals(allPerson.get(i).getName())) {
				judge=1;
				allPerson.remove(i);
				break;
			}
		}
		if(judge==1) {
			Pnumber--;
		}
		return parent;
	}

	public safeComponent deleteTeam(safeComponent team) {
		int judge=0;
		for(int i=0;i<allTeam.size();i++) {
			if(team.getName().equals(allTeam.get(i).getName())) {
				judge=1;
				allTeam.remove(i);
				break;
			}
		}
		if(judge==1) {
			Tnumber--;
		}
		return parent;
	}

	public ArrayList<safeLeaf> getPerson() {
		return allPerson;
	}

	public ArrayList<safeComponent> getTeam() {
		return allTeam;
	}
	
	public int getPnumber() {
		return Pnumber;
	}
	
	public int getTnumber() {
		return Tnumber;
	}

}
